package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.entity.jz.BLogs;
import com.sxbbc.common.core.mapper.jz.BLogsMapper;
import com.sxbbc.common.core.service.IBLogsService;
import com.sxbbc.common.core.utils.BasePage;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商家操作日志 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-05-08
 */
@Service
public class BLogsServiceImpl extends ServiceImpl<BLogsMapper, BLogs> implements IBLogsService {

	/**
     * 日志查询
     * @param log
     * @author YQQ
     */
    @Override
    public Page<BLogs> queryLogsList(BasePage<BLogs> page, BLogs log) {
        QueryWrapper<BLogs> wrapper = queryWrapper(log);
        if (page.isPaging()) {
            super.page(page, wrapper);
        } else {
            List<BLogs> list = super.list(wrapper);
            page.setRecords(list);
        }
        return page;
    }
    

    /**
     * 日志查询条件
     * @author YQQ
     */
    private QueryWrapper<BLogs> queryWrapper(BLogs log) {
        QueryWrapper<BLogs> wrapper = new QueryWrapper<>();
        wrapper.eq("bid",log.getBid());
        wrapper.orderByDesc("createtime");
        if(StringUtils.isNotBlank(log.getStart())){
            wrapper.gt("createtime",log.getStart());
        }
        if(StringUtils.isNotBlank(log.getEnd())){
            log.setEnd(log.getEnd() + " 23:59:59");
            wrapper.lt("createtime",log.getEnd());
        }
        return wrapper;
    }



}
